﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using LPV_POS.In;
using LPV_POS.Baocao;
using LPV_POS.Baocao.Ellic;
using CrystalDecisions.CrystalReports.Engine;
using LPV_POS.Baocao.Bixolon;
using System.Resources;
using System.Globalization;

namespace LPV_POS.mh_pos
{
    public partial class mh_banhang1_TachGopBan : DevExpress.XtraEditors.XtraForm
    {
        CultureInfo culture;
        string str_lang = "";
        //Boolean bInComPort = false;
        string DM_BAN_MA = "";
        string DM_BAN_MA2 = "";
        string DM_KHUVUC_MA = "";
        DataTable tbRight = new DataTable();
        DateTime timer1 = DateTime.Now;

        #region "Muti language"

        private void SetLanguage_banhang(string cultureName)
        {
            try
            {
                culture = CultureInfo.CreateSpecificCulture(cultureName);
                ResourceManager rm = new ResourceManager("LPV_POS.Muti_language.MyResource", typeof(mh_banhang1_TachGopBan).Assembly);
                rbtTachban.Text = rm.GetString("tachban", culture);
                rbtGopBan.Text = rm.GetString("gopban", culture);
                label1.Text = rm.GetString("khuvuc", culture);
                label2.Text = rm.GetString("ban", culture);
                chkGopMon.Text = rm.GetString("quanlykho", culture);
                bton_thuchien_1.Text = rm.GetString("dongy", culture);
                bton_thoat_1.Text = rm.GetString("thoat", culture);
             //   lbel_tencongty.Text = rm.GetString("tachgopban", culture);

                this.COL_OBJID1.Caption = rm.GetString("sophieu", culture);
                this.col_TONG_TIEN1.Caption = rm.GetString("tongcong", culture);
                this.gridColumn1.Caption = rm.GetString("sophieu", culture);
                this.gridColumn2.Caption = rm.GetString("tongcong", culture);

                //lbel_7.Font = new Font(lbel_7.Font.Name, 42);
                //lbel_8.Text = rm.GetString("thaydoingaylamviec", culture);
                //lbel_8.Font = new Font(lbel_8.Font.Name, 42);
                //lbel_9.Text = rm.GetString("thuchi", culture);
                //lbel_12.Text = rm.GetString("thoat", culture);
                //lbel_ngaylamviec.Text = rm.GetString("ngaylamviec", culture) + " " + Variable.ngay_lamviec.ToString("dd/MM/yyyy");

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Note");
            }
        }

        #endregion
        public mh_banhang1_TachGopBan(string _DM_BAN_MA, DateTime _timer1)
        {
            InitializeComponent();
            culture = CultureInfo.CurrentCulture;
            cpublic ocpublic = new cpublic();
            str_lang = ocpublic.Registry_Get("mh_main_lang");
            if (str_lang == "")
                str_lang = "vi-VN";

            switch (str_lang)
            {
                case "vi-VN":
                    lbel_tencongty.Text = "TÁCH / GỘP BÀN";
                    break;
                case "en-US":
                    lbel_tencongty.Text = "SPLIT / MERGE TABLES";
                    break;

            }
            timer1 = _timer1;
            DM_BAN_MA = _DM_BAN_MA;
            // -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -==
            // -== -== -== -== -== -== -== -== -==  DM_KHUVUC2
            // -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -==
            string sSQL = "SELECT OBJID, OBJNAME, GHICHU FROM DM_KHUVUC";
            thuvien othuvien = new thuvien();
            DataTable tbKhuVuc = othuvien.SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
            cboKhuVuc.Datasource = tbKhuVuc;
            othuvien.f_showdataoncombox(cboKhuVuc, tbKhuVuc, "OBJID", "OBJNAME");

            // -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -==
            // -== -== -== -== -== -== -== -== -==  DM_BAN_1
            // -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -==
            sSQL = "SELECT MAKHUVUC, OBJNAME FROM DM_BAN WHERE OBJID LIKE '" + DM_BAN_MA + "'";
            DataTable TB1 = othuvien.SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@Ssql" }, new object[] { sSQL });
            if (TB1.Rows.Count > 0)
            {
                DM_KHUVUC_MA = TB1.Rows[0]["MAKHUVUC"] + "";
                lbel_tencongty.Text = lbel_tencongty.Text + " (" + TB1.Rows[0]["OBJNAME"] + ")";
                lbel_tencongty.Tag = TB1.Rows[0]["OBJNAME"];
            }

            // -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -==
            // -== -== -== -== -== -== -== -== -==  BH_PHIEU_TMP_1
            // -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -==
            this.ShowData_tbLeft();

            bLoadForm = true;
        }
        public mh_banhang1_TachGopBan(string _DM_BAN_MA, DateTime _timer1, Boolean iGopBan)
        {
            InitializeComponent();
            timer1 = _timer1;
            DM_BAN_MA = _DM_BAN_MA;
            // -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -==
            // -== -== -== -== -== -== -== -== -==  DM_KHUVUC2
            // -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -==
            string sSQL = "SELECT OBJID, OBJNAME, GHICHU FROM DM_KHUVUC";
            thuvien othuvien = new thuvien();
            DataTable tbKhuVuc = othuvien.SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
            cboKhuVuc.Datasource = tbKhuVuc;
            othuvien.f_showdataoncombox(cboKhuVuc, tbKhuVuc, "OBJID", "OBJNAME");

            // -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -==
            // -== -== -== -== -== -== -== -== -==  DM_BAN_1
            // -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -==
            sSQL = "SELECT MAKHUVUC, OBJNAME FROM DM_BAN WHERE OBJID LIKE '" + DM_BAN_MA + "'";
            DataTable TB1 = othuvien.SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@Ssql" }, new object[] { sSQL });
            if (TB1.Rows.Count > 0)
            {
                DM_KHUVUC_MA = TB1.Rows[0]["MAKHUVUC"] + "";
                lbel_tencongty.Text = lbel_tencongty.Text + " (" + TB1.Rows[0]["OBJNAME"] + ")";
                lbel_tencongty.Tag = TB1.Rows[0]["OBJNAME"];
            }

            // -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -==
            // -== -== -== -== -== -== -== -== -==  BH_PHIEU_TMP_1
            // -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -==
            this.ShowData_tbLeft();
            rbtGopBan.Checked = iGopBan;
            rbtTachban.Visible = !iGopBan;

            bLoadForm = true;
        }
        public mh_banhang1_TachGopBan(string _DM_BAN_MA, DateTime _timer1, string _DM_BAN_MA2)
        {
            InitializeComponent();
           

          
            cboKhuVuc.Properties.ReadOnly = true;
            cboBan.Properties.ReadOnly = true;
            rbtGopBan.Enabled = false;
            rbtTachban.Enabled = false;

            timer1 = _timer1;
            DM_BAN_MA = _DM_BAN_MA;
            // -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -==
            // -== -== -== -== -== -== -== -== -==  DM_KHUVUC2
            // -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -==
            string sSQL = "SELECT OBJID, OBJNAME, GHICHU FROM DM_KHUVUC";
            thuvien othuvien = new thuvien();
            DataTable tbKhuVuc = othuvien.SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
            cboKhuVuc.Datasource = tbKhuVuc;
            othuvien.f_showdataoncombox(cboKhuVuc, tbKhuVuc, "OBJID", "OBJNAME");

            // -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -==
            // -== -== -== -== -== -== -== -== -==  DM_BAN_1
            // -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -==
            sSQL = "SELECT MAKHUVUC, OBJNAME FROM DM_BAN WHERE OBJID LIKE '" + DM_BAN_MA + "'";
            DataTable TB1 = othuvien.SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
            if (TB1.Rows.Count > 0)
            {
                DM_KHUVUC_MA = TB1.Rows[0]["MAKHUVUC"] + "";
                lbel_tencongty.Text = lbel_tencongty.Text + " (" + TB1.Rows[0]["OBJNAME"] + ")";
                lbel_tencongty.Tag = TB1.Rows[0]["OBJNAME"];
            }

            // -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -==
            // -== -== -== -== -== -== -== -== -==  BH_PHIEU_TMP_1
            // -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -== -==
            this.ShowData_tbLeft();
            DM_BAN_MA2 = _DM_BAN_MA2;
            this.ShowData_tbRight();
            bLoadForm = true;

        }
        void ShowData_tbLeft()
        {
            string sSQL = "SELECT DM_BAN_MA = " + DM_BAN_MA + ", OBJID, TONG_TIEN, EDIT = CAST( 0 AS BIT) FROM BH_PHIEU_TMP WHERE DM_BAN_MA LIKE '" + DM_BAN_MA + "' ";
            DataTable tbMain1 = new thuvien().SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
            gridControlLeft.DataSource = tbMain1;
        }

        void ShowData_tbRight()
        {
            string sSQL = "SELECT DM_BAN_MA, OBJID, TONG_TIEN, EDIT = CAST( 0 AS BIT) FROM BH_PHIEU_TMP WHERE DM_BAN_MA LIKE '" + DM_BAN_MA2 + "' ";
            tbRight = new thuvien().SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
            gridControlRight.DataSource = tbRight;
        }

        Boolean bLoadForm = false;
        private void mh_banhang1_TachGopBan_Load(object sender, EventArgs e)
        {
            cpublic ocpublic = new cpublic();
            
            if (str_lang == "")
                str_lang = "vi-VN";
            SetLanguage_banhang(str_lang);



            string DM_BAN_MA2TMP = DM_BAN_MA2;
            if (tbRight.Rows.Count == 0 && rbtTachban.Visible)
                this.rbtTachban_CheckedChanged(null, null);
            else
            {
                this.rbtGopBan.Checked = true;
                this.rbtGopBan_CheckedChanged(null, null);
            }
            cboKhuVuc._SetselectedID(DM_KHUVUC_MA);
            if (DM_BAN_MA2TMP != "")
                cboBan._SetselectedID(DM_BAN_MA2TMP);
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Dispose();
        }

        private void cboKhuVuc_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (bLoadForm)
            {
                DM_KHUVUC_MA = cboKhuVuc._GetselectedID();
                bLoadForm = false;
                cboBan.Text = "";
                this.ShowcboBan();
                bLoadForm = true;
            }
        }

        void ShowcboBan()
        {
            int trangthai = 1;//da co nguoi
            if (rbtTachban.Checked)
                trangthai = 0;//ban con trong

            string sSQL = "SELECT * " +
                          "FROM DM_BAN " +
                          "WHERE (MAKHUVUC LIKE '" + DM_KHUVUC_MA + "' " +
                          "     AND TRANGTHAI = " + trangthai +
                          "     AND OBJID NOT LIKE '" + DM_BAN_MA + "'" +
                          "     ) " +
                          "     OR " +
                          "     (" +
                          "         OBJID LIKE '" + DM_BAN_MA2 + "'" +
                          "     )" +
                          "ORDER BY CAST(OBJID AS INT)"
                          ;

            thuvien othuvien = new thuvien();
            DataTable tbBAN = othuvien.SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
            cboBan.Properties.Items.Clear();
            othuvien.f_showdataoncombox(cboBan, tbBAN, "OBJID", "OBJNAME");
            if (DM_BAN_MA2 != "")
                cboBan._SetselectedID(DM_BAN_MA2);
        }

        private void cboBan_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (bLoadForm)
            {
                bLoadForm = false;
                DM_BAN_MA2 = cboBan._GetselectedID();
                //string sSQL = "SELECT DM_BAN_MA = " + DM_BAN_MA + ", OBJID, TONG_TIEN, EDIT = CAST( 0 AS BIT) FROM BH_PHIEU_TMP WHERE DM_BAN_MA LIKE '" + DM_BAN_MA2 + "' ";
                //DataTable tbMain2 = new thuvien().SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
                //gridControlRight.DataSource = tbMain2;
                this.ShowData_tbRight();
                bLoadForm = true;
            }
            this.HienThi_chkGopMon();
        }

        private void rbtTachban_CheckedChanged(object sender, EventArgs e)
        {
            DataTable tbMain1 = (DataTable)gridControlLeft.DataSource;
            btnThucHien.Enabled = tbMain1.Rows.Count > 1;
            if (bLoadForm)
            {
                cboBan.Text = "";
                //if (tbRight.Rows.Count == 0)
                //    DM_BAN_MA2 = "";
                this.ShowData_tbLeft();
                this.ShowData_tbRight();
                this.ShowcboBan();
            }
            this.HienThi_chkGopMon();
        }
        private void rbtGopBan_CheckedChanged(object sender, EventArgs e)
        {
            DataTable tbMain1 = (DataTable)gridControlLeft.DataSource;
            btnThucHien.Enabled = tbMain1.Rows.Count > 0;
            if (bLoadForm)
            {
                cboBan.Text = "";
                //if (tbRight.Rows.Count == 0)
                //    DM_BAN_MA2 = "";
                this.ShowData_tbLeft();
                this.ShowData_tbRight();
                this.ShowcboBan();
            }
            this.HienThi_chkGopMon();
        }

        private void btnGo_Click(object sender, EventArgs e)
        {
            if (DM_BAN_MA != "" && DM_BAN_MA2 != "")
            {
                DataTable tbLeft = (DataTable)gridControlLeft.DataSource;
                tbRight = (DataTable)gridControlRight.DataSource;
                DataRow drLeft = (DataRow)gridViewLeft.GetDataRow(gridViewLeft.FocusedRowHandle);
                string maPhieuLeft = drLeft["OBJID"] + "";
                string TongTienLeft = drLeft["TONG_TIEN"] + "";
                if (maPhieuLeft != "")
                {
                    DataRow dr = tbRight.NewRow();
                    dr["OBJID"] = maPhieuLeft;
                    dr["TONG_TIEN"] = TongTienLeft;
                    dr["EDIT"] = true;
                    tbRight.Rows.Add(dr);
                    gridControlRight.Refresh();

                    foreach (DataRow drDel in tbLeft.Rows)
                        if (drDel["OBJID"] + "" == maPhieuLeft)
                        {
                            tbLeft.Rows.Remove(drDel);
                            break;
                        }
                    gridControlLeft.Refresh();

                }
            }
            this.HienThi_chkGopMon();
        }
        private void btnBack_Click(object sender, EventArgs e)
        {
            if (DM_BAN_MA != "" && DM_BAN_MA2 != "")
            {
                tbRight = (DataTable)gridControlRight.DataSource;
                DataTable tbLeft = (DataTable)gridControlLeft.DataSource;
                DataRow drRight = (DataRow)gridViewRight.GetDataRow(gridViewRight.FocusedRowHandle);
                string maPhieuRight = drRight["OBJID"] + "";
                string TongTienRight = drRight["TONG_TIEN"] + "";
                if (maPhieuRight != "")
                {
                    DataRow dr = tbLeft.NewRow();
                    dr["OBJID"] = maPhieuRight;
                    dr["TONG_TIEN"] = TongTienRight;
                    dr["EDIT"] = true;
                    tbLeft.Rows.Add(dr);
                    gridControlLeft.Refresh();

                    foreach (DataRow drDel in tbRight.Rows)
                        if (drDel["OBJID"] + "" == maPhieuRight)
                        {
                            tbRight.Rows.Remove(drDel);
                            break;
                        }
                    gridControlRight.Refresh();

                }

            }
            this.HienThi_chkGopMon();
        }

        void HienThi_chkGopMon()
        {
            chkGopMon.Visible = false;
            if (rbtGopBan.Checked)
            {
                if (DM_BAN_MA != "" && DM_BAN_MA2 != "")
                    chkGopMon.Visible = (gridViewLeft.RowCount == 0 || gridViewRight.RowCount == 0);
            }
            else
                chkGopMon.Checked = false;
        }

        string sTuBan_Ten = "";
        string sDenBan_Ten = "";
        private void btnThucHien_Click(object sender, EventArgs e)
        {
            try
            {
                if (DM_BAN_MA2 != "")
                {
                    thuvien othuvien = new thuvien();
                    int irt = -1;
                    if (!chkGopMon.Visible)
                        chkGopMon.Checked = false;

                    #region "   tbLeft"
                    DataTable tbLeft = (DataTable)gridControlLeft.DataSource;
                    foreach (DataRow dr in tbLeft.Rows)
                    {
                        //@BH_PHIEU_MA2 phieu GỐC
                        irt = othuvien.SP_Update("sp_mh_banhang",
                                        new string[] { "@flag", "@DM_BAN_MA", "@BH_PHIEU_MA", "@GOP_MON", "@BH_PHIEU_MA2" },
                                        new object[] { 13, DM_BAN_MA, dr["OBJID"], chkGopMon.Checked, tbLeft.Rows[0]["OBJID"] });//cap nhat PHIEU sang BAN_MOI
                        if (irt < 1)
                            return;
                    }
                    #endregion

                    #region "   tbRight"
                    tbRight = (DataTable)gridControlRight.DataSource;
                    foreach (DataRow dr in tbRight.Rows)
                    {
                        //@BH_PHIEU_MA2 phieu GỐC
                        irt = othuvien.SP_Update("sp_mh_banhang",
                                        new string[] { "@flag", "@DM_BAN_MA", "@BH_PHIEU_MA", "@GOP_MON", "@BH_PHIEU_MA2" },
                                        new object[] { 13, DM_BAN_MA2, dr["OBJID"], chkGopMon.Checked, tbRight.Rows[0]["OBJID"] });//cap nhat PHIEU sang BAN_MOI
                        if (irt < 1)
                            return;
                    }
                    #endregion

                    #region "   Update TRANG_THAI"
                    irt = othuvien.SP_Update("sp_mh_banhang",
                                            new string[] { "@flag", "@DM_BAN_MA", "@DM_BAN_MA2" },
                                            new object[] { 14, DM_BAN_MA, DM_BAN_MA2 });
                    if (irt < 1)
                        return;
                    #endregion


                    if (irt == 1)
                    {
                        #region     "tam thoi ko dung"
                        //string sTachGop = " tách ra ";
                        //if (rbtGopBan.Checked)
                        //    sTachGop = " gộp với ";
                        //sTuBan_Ten = lbel_tencongty.Tag + "";
                        //sDenBan_Ten = cboBan.Text;

                        //string Ngay = "* NGAY: " + timer1.ToString("dd-MM-yyyy HH:mm") + "*";
                        //string str = lbel_tencongty.Tag + sTachGop + cboBan.Text;
                        ////print_usb BEP
                        //thuvien tv = new thuvien();
                        //DataTable tb = tv.SP_SelectDataTable("sp_DM_MAYIN_BEP", null, null);
                        //DataView dv = tb.DefaultView;
                        //dv.Sort = "COMNAME";
                        //// in gop ban , in tach ban
                        //int vitri = dv.Find(new object[] { "USB" });
                        //int vitri_bixolon = dv.Find(new object[] { "BIXOLON" });
                        //if (vitri > -1 || vitri_bixolon > -1)
                        ////if (!bInComPort)
                        //{
                        //    #region "In bill tieng viet"
                        //    ReportDocument rpt;
                        //    if (vitri > -1)
                        //        rpt = new bc_BaoCao_Rong();
                        //    else
                        //        rpt = new bc_BaoCao_Rong_Bixolon();

                        //    rpt.DataDefinition.FormulaFields["formula1"].Text = "'" + Ngay + "'";
                        //    rpt.DataDefinition.FormulaFields["formula2"].Text = "'" + str + "'";

                        //    rpt.PrintToPrinter(0, true, 1, 100);
                        //    #endregion

                        //}
                        //else
                        //{
                        //    #region "   In tách gộp bàn"
                        //    DataTable tbDM_MAYIN_BEP = new thuvien().SP_SelectDataTable("sp_DM_MAYIN_BEP",
                        //                                                                new string[] { "@flag" },
                        //                                                                new object[] { 6 });
                        //    string _sPortname = ";";

                        //    for (int i1 = 0; i1 < tbDM_MAYIN_BEP.Rows.Count; i1++)
                        //    {
                        //        if (_sPortname.IndexOf(";" + tbDM_MAYIN_BEP.Rows[i1]["COMNAME"] + ";") < 0)
                        //            _sPortname = _sPortname + ";" + tbDM_MAYIN_BEP.Rows[i1]["COMNAME"] + ";";
                        //    }

                        //    PrintCOMs oPrintCOM = new PrintCOMs(PrintCOMs.Print_Type.Print_KitChen);
                        //    SerialPort_LPV[] SerialPort_LPVs = oPrintCOM.Print_Start();
                        //    if (SerialPort_LPVs != null && Variable.gsrlCOMBillport !=null)
                        //    {
                        //        foreach (SerialPort_LPV oSerialPort_LPV in Variable.gsrlCOMBillport)
                        //        {
                        //            if (oSerialPort_LPV != null && _sPortname.IndexOf(";" + oSerialPort_LPV.PortName + ";") >= 0)//&& oSerialPort_LPV.IsOpen)
                        //            {
                        //                if (!oSerialPort_LPV.IsOpen)//9999
                        //                    oSerialPort_LPV.Open();
                        //                //tbBH_PHIEU_CT_TMP.Select("(OBJID IS NULL OR OBJID = -1) AND DM_MAYIN_BEP_MA = '" + oSerialPort_LPV.OBJID + "'")
                        //                oPrintCOM.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Left, PrintCOMs.Fonts.Font_Double_Height, str, "", "", "");
                        //                oPrintCOM.Print_Content(oSerialPort_LPV, PrintCOMs.aligns.Align_Center, PrintCOMs.Fonts.Font_Normal, Ngay, "", "", "");
                        //                oPrintCOM.Print_Bottom(oSerialPort_LPV);

                        //                if (oSerialPort_LPV.IsOpen)
                        //                    oSerialPort_LPV.Close();
                        //                _sPortname = _sPortname.Replace(";" + oSerialPort_LPV.PortName + ";", "");
                        //            }
                        //        }
                        //    }
                        //    #endregion
                        //}
                        #endregion
                        //
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                }
                else if (rbtGopBan.Checked)
                    new mh_thongbao("Chọn bàn cần gộp", 2).ShowDialog();
                else if (rbtTachban.Checked)
                    new mh_thongbao("Chọn bàn cần tách ra", 2).ShowDialog();
            }
            catch (Exception ex)
            {
                new mh_thongbao(ex.Message, 2).ShowDialog();
            }
        }
    }
}